package com.ptma.android.client;

import java.io.File;
import java.io.InputStream;
import java.util.Properties;

public class AaptLoader {
	private static String PROPERTY_FILE = File.separator + "apktool.properties";

	public String getPlatformAapt(OS os) throws Exception {

		Properties prop = new Properties();
		InputStream in = AaptLoader.class.getClassLoader().getResourceAsStream(
				PROPERTY_FILE);
		prop.load(in);
		in.close();
		if (os == OS.WINDOWS) {
			return AaptLoader.class.getClassLoader()
					.getResource(prop.getProperty("aapt.windows")).getFile();
		} else if (os == OS.LINUX) {
			return AaptLoader.class
					.getClassLoader()
					.getResource(
							File.separator + prop.getProperty("aapt.linux"))
					.getFile();
		} else if (os == OS.MAC) {
			return AaptLoader.class.getClassLoader()
					.getResource(File.separator + prop.getProperty("aapt.mac"))
					.getFile();
		} else {

			throw new UnsupportedOperationException(
					"Operating system not supported");
		}

	}

	public static void main(String[] args) throws Exception {
		String filePath = new AaptLoader().getPlatformAapt(OS.getOS());
		System.out.println(filePath);
	}
}
